route.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { ApiPath } from "@/app/constant";
  2. import { NextRequest } from "next/server";
  3. import { handle as openaiHandler } from "../../openai";
  4. import { handle as azureHandler } from "../../azure";
  5. import { handle as googleHandler } from "../../google";
  6. import { handle as anthropicHandler } from "../../anthropic";
  7. import { handle as baiduHandler } from "../../baidu";
  8. import { handle as bytedanceHandler } from "../../bytedance";
  9. import { handle as alibabaHandler } from "../../alibaba";
  10. import { handle as moonshotHandler } from "../../moonshot";
  11. import { handle as stabilityHandler } from "../../stability";
  12. import { handle as iflytekHandler } from "../../iflytek";
  13. import { handle as deepseekHandler } from "../../deepseek";
  14. import { handle as xaiHandler } from "../../xai";
  15. import { handle as chatglmHandler } from "../../glm";
  16. import { handle as proxyHandler } from "../../proxy";
  17. async function handle(
  18. req: NextRequest,
  19. { params }: { params: { provider: string; path: string[] } },
  20. ) {
  21. const apiPath = `/api/${params.provider}`;
  22. console.log(`[${params.provider} Route] params `, params);
  23. switch (apiPath) {
  24. case ApiPath.Azure:
  25. return azureHandler(req, { params });
  26. case ApiPath.Google:
  27. return googleHandler(req, { params });
  28. case ApiPath.Anthropic:
  29. return anthropicHandler(req, { params });
  30. case ApiPath.Baidu:
  31. return baiduHandler(req, { params });
  32. case ApiPath.ByteDance:
  33. return bytedanceHandler(req, { params });
  34. case ApiPath.Alibaba:
  35. return alibabaHandler(req, { params });
  36. // case ApiPath.Tencent: using "/api/tencent"
  37. case ApiPath.Moonshot:
  38. return moonshotHandler(req, { params });
  39. case ApiPath.Stability:
  40. return stabilityHandler(req, { params });
  41. case ApiPath.Iflytek:
  42. return iflytekHandler(req, { params });
  43. case ApiPath.DeepSeek:
  44. return deepseekHandler(req, { params });
  45. case ApiPath.XAI:
  46. return xaiHandler(req, { params });
  47. case ApiPath.ChatGLM:
  48. return chatglmHandler(req, { params });
  49. case ApiPath.OpenAI:
  50. return openaiHandler(req, { params });
  51. default:
  52. return proxyHandler(req, { params });
  53. }
  54. }
  55. export const GET = handle;
  56. export const POST = handle;
  57. export const runtime = "edge";
  58. export const preferredRegion = [
  59. "arn1",
  60. "bom1",
  61. "cdg1",
  62. "cle1",
  63. "cpt1",
  64. "dub1",
  65. "fra1",
  66. "gru1",
  67. "hnd1",
  68. "iad1",
  69. "icn1",
  70. "kix1",
  71. "lhr1",
  72. "pdx1",
  73. "sfo1",
  74. "sin1",
  75. "syd1",
  76. ];